#include "stdafx.h"
#include "ShaderResource.h"

using namespace System::Runtime::InteropServices;

namespace Reign
{namespace Video
{namespace D3D10
{
	#pragma region Properties
	string^ ShaderResource::Name::get() {return name;}
	#pragma endregion

	#pragma region Contructors
	ShaderResource::ShaderResource(VideoI^ video, ID3D10ShaderResourceView** vertexResources, ID3D10ShaderResourceView** pixelResources, int vertexIndex, int pixelIndex, string^ name)
	{
		this->video = (Video^)video;

		this->vertexResources = vertexResources;
		this->pixelResources = pixelResources;

		this->vertexIndex = vertexIndex;
		this->pixelIndex = pixelIndex;

		this->name = name;
	}
	#pragma endregion

	#pragma region Methods
	void ShaderResource::Set(Texture2DI^ resource)
	{
		Texture2D^ texture = (Texture2D^)resource;
		if (vertexIndex != -1)
		{
			vertexResources[vertexIndex] = texture->ShaderResource;
			video->currentVertexResources[vertexIndex] = texture->ShaderResource;
		}
		if (pixelIndex != -1)
		{
			pixelResources[pixelIndex] = texture->ShaderResource;
			video->currentPixelResources[pixelIndex] = texture->ShaderResource;
		}
	}

	void ShaderResource::Set(Texture3DI^ resource)
	{
		Texture3D^ texture = (Texture3D^)resource;
		if (vertexIndex != -1)
		{
			vertexResources[vertexIndex] = texture->ShaderResource;
			video->currentVertexResources[vertexIndex] = texture->ShaderResource;
		}
		if (pixelIndex != -1)
		{
			pixelResources[pixelIndex] = texture->ShaderResource;
			video->currentPixelResources[pixelIndex] = texture->ShaderResource;
		}
	}
	#pragma endregion
}
}
}